package top.likeqc.leetcode.editor.cn;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @see <a href="https://leetcode.cn/problems/finding-the-users-active-minutes">leetcode题库</a>
 */
public class FindingTheUsersActiveMinutes {
    public static void main(String[] args) {
        Solution solution = new FindingTheUsersActiveMinutes().new Solution();
    }
    // leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int[] findingUsersActiveMinutes(int[][] logs, int k) {
            Map<Integer, Set<Integer>> map = new HashMap<>();
            for (int i = 0; i < logs.length; i++) {
                Set<Integer> set = map.getOrDefault(logs[i][0], new HashSet<>());
                set.add(logs[i][1]);
                map.put(logs[i][0], set);
            }

            int[] answer = new int[k];
            map.values()
                    .forEach(
                            set -> {
                                if (set.size() > 0) {
                                    answer[set.size() - 1]++;
                                }
                            });

            return answer;
        }
    }
    // leetcode submit region end(Prohibit modification and deletion)

}
